package nl.hanze.designpatterns.mvc.view;

import java.awt.event.ActionEvent;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.SpringLayout;

import nl.hanze.designpatterns.mvc.model.MainModel;

public class SelectedTicketView extends View {
	
	private SpringLayout layout;
	private JLabel userLabel;
	private JLabel callerLabel;
	private JLabel descriptionLabel;
	private JLabel datumLabel;
	private JLabel username;
	private JTextField callerName;
	private JTextArea description;
	private JTextField datum;
	private JScrollPane scrollPane;
	private JButton submitButton;
	private MainModel model;
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	public SelectedTicketView(MainModel model){
		this.init(model);
		this.addItems();
		this.locateItems();
	}
	
	private void init(MainModel model){
		this.setModel(model);
		this.layout = new SpringLayout();
		this.setBorder(BorderFactory.createTitledBorder("Selected Ticket"));
		this.setLayout(layout);		
		
		this.userLabel = new JLabel("Username: ");
		this.callerLabel = new JLabel("Caller: ");
		this.descriptionLabel = new JLabel("Description: ");
		this.datumLabel = new JLabel("Datum: ");
		
		this.username = new JLabel();
		this.callerName = new JTextField(22);
		this.description = new JTextArea(15, 21);
		
		this.description.setBorder(BorderFactory.createLoweredSoftBevelBorder());
		this.description.setWrapStyleWord(true);
		this.description.setLineWrap(true);
		
		this.scrollPane = new JScrollPane(this.description);
		this.scrollPane.setVisible(true);
		
		this.datum = new JTextField(22);
		
		this.submitButton = new JButton("submit");
		this.submitButton.setActionCommand("submitChanges");
		this.submitButton.addActionListener(this);
	}
	
	private void addItems(){
		this.add(this.userLabel);
		this.add(this.username);
		this.add(this.callerLabel);
		this.add(this.callerName);
		this.add(this.descriptionLabel);
		this.add(this.scrollPane);
		this.add(this.datumLabel);
		this.add(this.datum);
		this.add(this.submitButton);
	}
	
	private void locateItems(){
		
		//userLabel position
		this.layout.putConstraint(SpringLayout.WEST, this.userLabel, 40, SpringLayout.WEST, this);
		this.layout.putConstraint(SpringLayout.NORTH, this.userLabel, 60, SpringLayout.NORTH, this);
		//username position
		this.layout.putConstraint(SpringLayout.WEST,this.username, 110, SpringLayout.WEST, this);
		this.layout.putConstraint(SpringLayout.NORTH, this.username, 60, SpringLayout.NORTH, this);
		//callerLabel position
		this.layout.putConstraint(SpringLayout.WEST, this.callerLabel, 40, SpringLayout.WEST, this);
		this.layout.putConstraint(SpringLayout.NORTH, this.callerLabel, 100, SpringLayout.NORTH, this);
		//callerName position
		this.layout.putConstraint(SpringLayout.WEST, this.callerName, 110, SpringLayout.WEST, this);
		this.layout.putConstraint(SpringLayout.NORTH, this.callerName, 100, SpringLayout.NORTH, this);
		//descriptionLabel position
		this.layout.putConstraint(SpringLayout.WEST, this.descriptionLabel, 40, SpringLayout.WEST, this);
		this.layout.putConstraint(SpringLayout.NORTH, this.descriptionLabel, 130, SpringLayout.NORTH, this);
		//description position
		this.layout.putConstraint(SpringLayout.WEST, this.scrollPane, 114, SpringLayout.WEST, this);
		this.layout.putConstraint(SpringLayout.NORTH, this.scrollPane, 130, SpringLayout.NORTH, this);
		//datumLabel position
		this.layout.putConstraint(SpringLayout.WEST, this.datumLabel, 40, SpringLayout.WEST, this);
		this.layout.putConstraint(SpringLayout.NORTH, this.datumLabel, 390, SpringLayout.NORTH, this);
		//datumLabel position
		this.layout.putConstraint(SpringLayout.WEST, this.datum, 110, SpringLayout.WEST, this);
		this.layout.putConstraint(SpringLayout.NORTH, this.datum, 390, SpringLayout.NORTH, this);
		//submitButton position
		this.layout.putConstraint(SpringLayout.WEST, this.submitButton, 280, SpringLayout.WEST, this);
		this.layout.putConstraint(SpringLayout.NORTH, this.submitButton, 415, SpringLayout.NORTH, this);
	}
	

	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		System.out.println(e.getActionCommand());
		
	}

	public MainModel getModel() {
		return model;
	}

	public void setModel(MainModel model) {
		this.model = model;
	}
	

}
